package com.nit.mapper;

import com.nit.dto.UserCodeDTO;
import org.apache.ibatis.annotations.*;

public interface UserCodeMapper {

    @Insert("INSERT INTO " +
            "tb_user_code (uc_code, is_used, gmt_expire) " +
            "VALUES (#{userCodeDTO.ucCode},#{userCodeDTO.isUsed},#{userCodeDTO.gmtExpire}) ")
    @Options(useGeneratedKeys = true, keyColumn = "uc_id", keyProperty = "ucId")
    Long add(@Param("userCodeDTO") UserCodeDTO userCodeDTO);

    @Select("SELECT " +
            "uc_id, uc_code, is_used, gmt_expire " +
            "FROM tb_user_code " +
            "WHERE uc_id = #{ucId} ")
    UserCodeDTO queryByUcId(@Param("ucId") Long ucId);

    @Update("UPDATE " +
            "tb_user_code " +
            "SET is_used = 1 " +
            "WHERE uc_id = #{ucId} ")
    Integer setIsUsed(@Param("ucId") Long ucId);

}
